package org.smartjava.concurrent.juc;

import org.smartjava.util.PrintUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class FutureExample {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        String fruit = "苹果";
        List<String> list = new ArrayList<>();
        Future<List<String>> caculateFuture = executor.submit(() -> list.add(fruit), list);
        List<String> result = caculateFuture.get();
        PrintUtil.print(result);


    }

}
